package handlers

import (
	"github.com/labstack/echo/v4"

	"night-school-api/models"
	"night-school-api/utils"
	"night-school-api/database"
)

type SuggestionRequest struct {
	Content string `json:"content" validate:"required,min=10"`
}

func Suggest(c echo.Context) error {
	uid := c.Get("uid").(int)

	var req models.Suggestion
	if err := c.Bind(&req); err != nil {
		return utils.JSONError(c, "参数错误"+err.Error())
	}

	if err := c.Validate(&req); err != nil {
		return err
	}

	db := database.DB

	req.UserID = uid
	rs := db.Model(&models.Suggestion{}).Create(&req)


	if rs.Error != nil {
		return utils.JSONError(c, "提交失败，请联系运营人员！")
	} else {
		return utils.JSONSuccess(c, nil, "提交成功，感谢您的建议！")
	}
}